package com.ruoyi.camera.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camera.domain.AiCamera;
import com.ruoyi.camera.service.IAiCameraService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 摄像头识别Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@Controller
@RequestMapping("/AI/camera")
public class AiCameraController extends BaseController
{
    private String prefix = "AI/camera";

    @Autowired
    private IAiCameraService aiCameraService;

    @RequiresPermissions("AI:camera:view")
    @GetMapping()
    public String camera()
    {
        return prefix + "/camera";
    }

    /**
     * 查询摄像头识别列表
     */
    @RequiresPermissions("AI:camera:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AiCamera aiCamera)
    {
        startPage();
        List<AiCamera> list = aiCameraService.selectAiCameraList(aiCamera);
        return getDataTable(list);
    }

    /**
     * 导出摄像头识别列表
     */
    @RequiresPermissions("AI:camera:export")
    @Log(title = "摄像头识别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AiCamera aiCamera)
    {
        List<AiCamera> list = aiCameraService.selectAiCameraList(aiCamera);
        ExcelUtil<AiCamera> util = new ExcelUtil<AiCamera>(AiCamera.class);
        return util.exportExcel(list, "摄像头识别数据");
    }

    /**
     * 新增摄像头识别
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存摄像头识别
     */
    @RequiresPermissions("AI:camera:add")
    @Log(title = "摄像头识别", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AiCamera aiCamera)
    {
        return toAjax(aiCameraService.insertAiCamera(aiCamera));
    }

    /**
     * 修改摄像头识别
     */
    @RequiresPermissions("AI:camera:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AiCamera aiCamera = aiCameraService.selectAiCameraById(id);
        mmap.put("aiCamera", aiCamera);
        return prefix + "/edit";
    }

    /**
     * 修改保存摄像头识别
     */
    @RequiresPermissions("AI:camera:edit")
    @Log(title = "摄像头识别", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AiCamera aiCamera)
    {
        return toAjax(aiCameraService.updateAiCamera(aiCamera));
    }

    /**
     * 删除摄像头识别
     */
    @RequiresPermissions("AI:camera:remove")
    @Log(title = "摄像头识别", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aiCameraService.deleteAiCameraByIds(ids));
    }
}
